{{ $page := . }}

<details class="docnav" open>
    <summary class="docnav-title">Docs</summary>
    <nav>
        <ol class="docnav-list">

            <li class="{{ if eq .Site.Home.File.UniqueID $page.File.UniqueID }}active {{ end }}">
                <a href="{{ .Site.Home.Permalink | relURL }}"> {{ .Site.Home.Params.nav_title }}</a>
            </li>

            {{ $docs := sort (where .Site.Pages "Section" "docs") ".Params.weight" }}
            {{ range where $docs ".Params.nav_section" "Root" }}
            <li class="{{ if eq .File.UniqueID $page.File.UniqueID }}active {{ end }}">
                <a href="{{ .Permalink | relURL }}"> {{ .Params.nav_title }}</a>
            </li>
            {{ end }}

            {{ $groups := slice }}
            {{ range $docs }}
            {{ if not (eq .Params.nav_section "Root") }}
            {{ $groups = $groups | append .Params.nav_section }}
            {{ end }}
            {{ end }}
            {{ $groups = uniq $groups }}

            {{ range $groups }}
            <li>
                <p class="docnav-title">{{ . }}</p>
                <ol class="docnav-list">
                    {{ range where $docs ".Params.nav_section" . }}
                    <li class="{{ if eq .File.UniqueID $page.File.UniqueID }}active {{ end }}">
                        <a href="{{ .Permalink | relURL }}"> {{ .Params.nav_title }}</a>
                    </li>
                    {{ end }}
                </ol>
            </li>
            {{ end }}
        </ol>
    </nav>
</details>